#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int thirdMax(vector<int>& nums) {
        const long long min_inf = -2147483649;
        long long ans[3] = {min_inf, min_inf, min_inf};
        for(int i = 0; i < nums.size(); i++){
            if(nums[i] >= ans[0]){
                if(nums[i] == ans[0])continue;
                ans[2] = ans[1];
                ans[1] = ans[0];
                ans[0] = nums[i];
            }
            else if(nums[i] >= ans[1]){
                if(nums[i] == ans[1])continue;
                ans[2] = ans[1];
                ans[1] = nums[i];
            }
            else if(nums[i] >= ans[2])ans[2] = nums[i];
        }
        return (ans[2] != min_inf ? ans[2] : ans[0]);
    }
};

/**
 * 2021.10.6
 * 用三个变量存第一大 第二大  第三大
 */